package com.example.safeassistan.message.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.safeassistan.R;
import com.example.safeassistan.base.BaseActivity;
import com.example.safeassistan.message.adapter.ChatAdapter;
import com.example.safeassistan.message.model.MessageDetail;
import com.example.safeassistan.widget.WarningDialog;

import java.util.ArrayList;
import java.util.List;

public class Activity_Message_Detail_Send extends BaseActivity implements View.OnClickListener {
    private int id=0;
    private MessageDetail model;
    private TextView tvCreateTime;
    private TextView tvContent;
    private TextView tvTitle;
    private ImageView _barIvRight;
    private RecyclerView rcMsg;
    private ChatAdapter adapter;
    private List<Integer> data;

    public static void actionStart(Context context,int id) {
        Intent intent = new Intent(context, Activity_Message_Detail_Send.class);
        intent.putExtra("id",id);
        context.startActivity(intent);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id._barIvRight:
                //删除
                WarningDialog dialog=new WarningDialog(getContext(),"确认要删除该条消息吗？","取消","确定","");
                dialog.setClicklistener(new WarningDialog.ClickListenerInterface() {
                    @Override
                    public void doCancel() {
                        dialog.dismiss();
                    }

                    @Override
                    public void doConfirm() {
                        dialog.dismiss();
                    }
                });
                dialog.show();
                break;
        }
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setAndroidNativeLightStatusBar(true);
    }

    @Override
    protected int setLayoutResourceID() {
        return R.layout.activity_message_detail_send;
    }

    @Override
    protected void initView() {
        setTitleText("内容详情");
        id=getIntent().getIntExtra("id",0);
        _barIvRight=findViewById(R.id._barIvRight);
        _barIvRight.setImageResource(R.mipmap.icon_delete_black);
        _barIvRight.setVisibility(View.VISIBLE);
        _barIvRight.setOnClickListener(this::onClick);
        tvCreateTime=findViewById(R.id.tvCreateTime);
        tvTitle=findViewById(R.id.tvTitle);
        tvContent=findViewById(R.id.tvContent);
        rcMsg=findViewById(R.id.rcMsg);
       // getData();

        data=new ArrayList<>();
        for(int i=0;i<15;i++){
            data.add(i);
        }
        adapter=new ChatAdapter(data);
        rcMsg.setLayoutManager(new LinearLayoutManager(getContext()));
        rcMsg.setAdapter(adapter);
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()){
                    case R.id.tvCancel:
                        //撤销回复
                        WarningDialog dialog=new WarningDialog(getContext(),"是否撤销该条回复消息？","取消","确定","");
                        dialog.setClicklistener(new WarningDialog.ClickListenerInterface() {
                            @Override
                            public void doCancel() {
                                dialog.dismiss();
                            }

                            @Override
                            public void doConfirm() {
                                dialog.dismiss();
                            }
                        });
                        dialog.show();
                        break;
                }
            }
        });
    }

    //设置数据
    public void setView(){
        tvContent.setText(model.getData().getContent());
        tvCreateTime.setText(model.getData().getCreateTime());
        tvTitle.setText(model.getData().getTitle());
    }

    //获取资料详情
//    public void getData(){
//        Map<String, String> map = new HashMap<>();
//        map.put("messageId", String.valueOf(id));
//        map.put("userId",getUserId(getContext()));
//        new HttpRequest(getContext()).doPost(UrlConstants.userMessage_detail, "", map, new HttpStringCallBack() {
//            @RequiresApi(api = Build.VERSION_CODES.M)
//            @Override
//            public void onSuccess(Object result) {
//                String datas = result.toString();
//                JSONObject jsonObject = null;
//                try {
//                    jsonObject = new JSONObject(datas);
//                    String message = jsonObject.getString("message");
//                    int code = jsonObject.getInt("code");
//                    if (code == 200) {
//                        Object obj = JsonUtils.fromJson(result.toString(), MessageDetail.class);
//                        if (obj instanceof MessageDetail) {
//                            model=(MessageDetail)obj;
//                            setView();
//                        }
//                    }else {
//                        Toast.makeText(Activity_Message_Detail.this,message,Toast.LENGTH_SHORT).show();
//                    }
//                }catch (Exception e){
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public void onFailure(int code, String msg) {
//            }
//        });
//    }

    @Override
    protected void initData() {
    }

    @Override
    protected int getTitleBarType() {
        return TITLEBAR_RIGHT_IMG;
    }
}